﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ComposantMappage
{
    class MAPP_TB_PERSONNE
    {
        private FactoryMessage.STGMSG oMsg;
        private string rq_sql;

        public FactoryMessage.STGMSG select()
        {
            this.rq_sql = "SELECT [id_personne],[nom],[prenom],[id_site],[login],[psw] FROM [DB_A2_ARCHINET_P2].[dbo].[TB_PERSONNE];";
            this.oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", new object[] { (object)rq_sql }, "", "", "", true, "");

            return this.oMsg;
        }

        public FactoryMessage.STGMSG select_login_psw(FactoryMessage.STGMSG oMsg)
        {
            string login;
            string psw;

            login = (string)oMsg.Data[0];
            psw = (string)oMsg.Data[1];
            this.rq_sql = "SELECT [login],[psw] FROM [DB_A2_ARCHINET_P2].[dbo].[TB_PERSONNE] WHERE [login] ='" + login + "' AND [psw] ='" + psw + "';";
            this.oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", new object[] { (object)rq_sql }, "", "", "", true, "");

            return this.oMsg;
        }
        public FactoryMessage.STGMSG select_emp_site_psw(FactoryMessage.STGMSG oMsg)
        {
            string site;
            site = (string)oMsg.Data[0];

            this.rq_sql = "SELECT id_personne, nom, prenom FROM TB_PERSONNE WHERE(id_site = '" + site + "');";
            this.oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", new object[] { (object)rq_sql }, "", "", "", true, "");

            return this.oMsg;
        }

        public FactoryMessage.STGMSG insert_nvPersonne(FactoryMessage.STGMSG oMsg)
        {
            string nom;
            string prenom;
            string id_site;
            string login;
            string psw;

            nom = (string)oMsg.Data[0];
            prenom = (string)oMsg.Data[1];
            id_site = (string)oMsg.Data[2];
            login = (string)oMsg.Data[3];
            psw = (string)oMsg.Data[4];

            this.rq_sql = "INSERT INTO TB_PERSONNE (nom, prenom, id_site, login, psw) VALUES ('" + nom + "', '" + prenom + "', '" + id_site + "', '" + login + "', '" +
           psw + "') ;";
            this.oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", new object[] { (object)rq_sql }, "", "", "", true, "");

            return this.oMsg;
        }
    }
}
